using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Management;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
using System.IO;
using System.Web.Security;
using System.Timers;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Web.Mail;

/// <summary>
/// Summary description for users
/// </summary>
public class users
{
	public users()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static DataSet View_sp()
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT top 9* FROM SB001 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_sp_chitiet(int id_ma)
    {
        string kn;
        int id;
        id = id_ma;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM SB001 where ID=36", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Sach(int id )
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=2 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);     

        cn.Close();
        return ds;
    }
    public static DataSet View_Giay(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=3 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Dienthoai(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=4 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Maychuphinh(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=5 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Maytinh(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=6 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Trangsuc(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=7 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Banghe(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=10 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Mypham(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=11 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Nuoc(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=12 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_Capsach(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM DM002  where ID_DM001=13 order by ID desc ", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }
    public static DataSet View_chitiet(int id)
    {
        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM SB001 where ID=1 order by ID desc ", cn);
        
        DataSet ds = new DataSet();
        db.Fill(ds);

        cn.Close();
        return ds;
    }

  //  public static int Add_sp_ban(int id_sp, int id_kh, string tensp, string mota,string chitiet, string hinh1,string hinh2, string hinh3, float gia_kd, float gia_san, float gia_mua, float gia_nang,DateTime bd, DateTime kt, int hinhthuc, string diadiem, float chiphi, string quidinh, float thue)
    public static int Add_sp_ban(int id_sp, int id_kh, string tensp, string mota, string chitiet, string hinh1, string hinh2, string hinh3, float gia_kd, float gia_san, float gia_mua, float gia_nang, DateTime bd,int ngay,int thang,int nam,int gio,int phut)  
    {
        string kn;
        string sql;
        string up;
        int rs;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
       // sql = "insert into SB001(ID_DM002,ID_KH001,TenSP,MoTa,Chitiet,HinhMinhHoa,HinhMinhHoa1,HinhMinhHoa2,GiaKhoiDiem,GiaSan,GiaMuaNgay,KhoanCachNangGia,ThoiGianBD,ThoiGianKT,ViTriSP,ID_TT001,DiaDiem,ChiPhiPS,QuyDinh,Thue) values(@id_sp,@id_kh,@tensp,@mota,@chitiet,@hinh1,@hinh2,@hinh3,@gia_kd,@gia_san,@gia_mua,@gia_nang,@bd,@kt,@hinhthuc,@diadiem,@chiphi,@quidinh,@thue)";
        sql = "insert into SB001(ID_DM002,ID_KH001,TenSP,MoTa,Chitiet,HinhMinhHoa,HinhMinhHoa1,HinhMinhHoa2,GiaKhoiDiem,GiaSan,GiaMuaNgay,KhoangCachNangGia,ThoiGianBD,Ngay,Thang,Nam,Gio,Phut) values(@id_sp,@id_kh,@tensp,@mota,@chitiet,@hinh1,@hinh2,@hinh3,@gia_kd,@gia_san,@gia_mua,@gia_nang,@bd,@ngay,@thang,@nam,@gio,@phut)";
        SqlCommand cm = new SqlCommand(sql, cn);
        cm.Parameters.Add("@id_sp",id_sp);
        cm.Parameters.Add("@id_kh",id_kh);
        cm.Parameters.Add("@tensp", tensp);
        cm.Parameters.Add("@mota", mota);
        cm.Parameters.Add("@chitiet", chitiet);
        cm.Parameters.Add("@hinh1", hinh1);
        cm.Parameters.Add("@hinh2", hinh2);
        cm.Parameters.Add("@hinh3", hinh3);
        cm.Parameters.Add("@gia_kd", gia_kd);
        cm.Parameters.Add("@gia_san", gia_san);
        cm.Parameters.Add("@gia_mua", gia_mua);
        cm.Parameters.Add("@gia_nang", gia_nang);
        cm.Parameters.Add("@bd", bd);
        cm.Parameters.Add("@ngay", ngay);
        cm.Parameters.Add("@thang", thang);
        cm.Parameters.Add("@nam", nam);
        cm.Parameters.Add("@gio", gio);
        cm.Parameters.Add("@phut", phut);

        //cm.Parameters.Add("@kt",kt);
        //cm.Parameters.Add("@hinhthuc",hinhthuc);
        //cm.Parameters.Add("@diadiem",diadiem);
        //cm.Parameters.Add("@chiphi",chiphi);
        //cm.Parameters.Add("@quidinh",quidinh);
        //cm.Parameters.Add("@thue",thue);
        
        rs = (int)cm.ExecuteNonQuery();
        cn.Close();
        return rs;
    }
    public static string Select_Hoten(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select HoTen from KH001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static string Select_CMND(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select CMND from KH001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static string Select_Diachi(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select DiaChi from KH001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static string Select_Chuthe(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select HoTen from KH002 where ID_01=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static string Select_Ma(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Ma from KH002 where ID_01=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static string Select_Thang(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Thang from KH002 where ID_01=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static string Select_Nam(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Nam from KH002 where ID_01=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static int Ngay(int id)
    {
        int count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Ngay from SB001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (int)cmd.ExecuteScalar();
        return count;
    }
    public static int Thang(int id)
    {
        int count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Thang from SB001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (int)cmd.ExecuteScalar();
        return count;
    }
    public static int Nam(int id)
    {
        int count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Nam from SB001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (int)cmd.ExecuteScalar();
        return count;
    }
    public static int Gio(int id)
    {
        int count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Gio from SB001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (int)cmd.ExecuteScalar();
        return count;
    }
    public static int Phut(int id)
    {
       int count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Phut from SB001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (int)cmd.ExecuteScalar();
        return count;
    }
    public static string Select_Email(int id)
    {
        string count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select Email from KH001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        count = (string)cmd.ExecuteScalar();
        return count;
    }
    public static DateTime Select_Ngaysinh(int id)
    {
        DateTime counts;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("Select NTNS from KH001 where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        //cmd.Parameters.Add("@view",view);
        counts = (DateTime)cmd.ExecuteScalar();
        return counts;
    }
    //public static int Update_user(int id, string hoten, DateTime ngaysinh,string cmnd,string diachi,string email)
    //{
    //    int count;
    //    string kn;
    //    kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
    //    SqlConnection cn = new SqlConnection(kn);
    //    cn.Open();
    //    SqlCommand cmd = new SqlCommand("update KH001 set HoTen=@hoten,NTNS=@ngaysinh,CMND=@cmnd,DiaChi=@diachi,Email=@email where ID=@id", cn);
    //    cmd.Parameters.Add("@id", id);
    //    cmd.Parameters.Add("@hoten",hoten);
    //    cmd.Parameters.Add("@ngaysinh",ngaysinh);
    //    cmd.Parameters.Add("@cmnd", cmnd);
    //    cmd.Parameters.Add("@diachi", diachi);
    //    cmd.Parameters.Add("@email",email);
    //    count = (int)cmd.ExecuteNonQuery();
    //    return count;
    //}
    public static int Update_user(int id, string hoten, DateTime ngaysinh, string cmnd, string diachi, string email)
    {
        int count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("update KH001 set HoTen=@hoten,NTNS=@ngaysinh,CMND=@cmnd,DiaChi=@diachi,Email=@email where ID=@id", cn);
        cmd.Parameters.Add("@id", id);
        cmd.Parameters.Add("@hoten", hoten);
        cmd.Parameters.Add("@ngaysinh", ngaysinh);
        cmd.Parameters.Add("@cmnd", cmnd);
        cmd.Parameters.Add("@diachi", diachi);
        cmd.Parameters.Add("@email", email);
        count = (int)cmd.ExecuteNonQuery();
        return count;
    }
    public static int Update_The(int id, string hoten, string loaithe, string ma, string th, string nm, string mathe)
    {
        int count;
        string kn;
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlCommand cmd = new SqlCommand("update KH002 set HoTen=@hoten,Ma=@ma,LoaiThe=@loaithe,MaThe=@mathe,Thang=@th,Nam=@nm where ID_01=@id", cn);
        cmd.Parameters.Add("@id", id);
        cmd.Parameters.Add("@hoten", hoten);
        cmd.Parameters.Add("@ma", ma);
        cmd.Parameters.Add("@loaithe", loaithe);
        cmd.Parameters.Add("@mathe", mathe);
        cmd.Parameters.Add("@th", th);
        cmd.Parameters.Add("@nm", nm);
        count = (int)cmd.ExecuteNonQuery();
        return count;
    }
    public static DataSet Loaithanhtoan()
    {



        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM TT001 order by HTTT Desc", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);
        cn.Close();
        return ds;
    }
    public static DataSet Dia_diem()
    {



        string kn;
        //SqlCommand cm = new SqlCommand();
        kn = ConfigurationManager.ConnectionStrings["db_connection"].ToString();
        SqlConnection cn = new SqlConnection(kn);
        cn.Open();
        SqlDataAdapter db = new SqlDataAdapter("SELECT * FROM TT002 order by DienGiai asc", cn);
        DataSet ds = new DataSet();
        db.Fill(ds);
        cn.Close();
        return ds;
    }

}

